package com.jianxiu.utils;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

/**
 * Created by qiao on 2017/4/22.
 */
public class LocalCacheUtils {
    static LoadingCache<String, String> cache = CacheBuilder.newBuilder().maximumSize(1000)
            .expireAfterWrite(110, TimeUnit.MINUTES)
            .build(new CacheLoader<String, String>() {
                @Override
                public String load(String s) throws Exception {
                    return "";
                }
            });

    public static void add(String key, String value) {
        cache.put(key, value);
    }

    public static String get(String key) {
        try {
            return cache.get(key);
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return "";
    }
}
